import { IViewItem } from "@/model/frame/IViewItem";
import { ViewItems } from "@/model/frame/ViewItems";
import { Permissions } from "./IPermissionConfig";
import { PermissionTool } from "@/utils/frame/PermissionTool";
import ConfigPermission from "@/frame-config/permission";
import FramePermission from "@/model/frame/FramePermission";
import FrameConfig from "./FrameConfig";

export interface IAppState {
  name: string;
  drawer: boolean;
  viewItems: IViewItem[];
  permissions: Permissions;
  defaultPermissions: Permissions;
  mockInited: boolean;
}

export class AppState implements IAppState {
  name = FrameConfig.APP_NAME;
  drawer = false;
  viewItems = ViewItems.instance().groups;
  permissions: Permissions = [];
  defaultPermissions: Permissions = [];
  mockInited = false;

  constructor() {
    this.permissions = [];
    this.initPermission();
  }

  private initPermission(): void {
    this.defaultPermissions.push(
      ...PermissionTool.getRoutePermissionCodes(
        [...FramePermission.route, ...ConfigPermission.route],
        this.name
      ),
      ...PermissionTool.getDirPermissionCodes(
        [...FramePermission.dir, ...ConfigPermission.dir],
        this.name
      )
    );
    // 初始化一些默认权限
    this.permissions.push(...this.defaultPermissions);
  }
}
